package Chapter5;

public class Work4 extends Thread{
	private int startnum;
	static int sum;
	public Work4(int startnum) {
		this.startnum=startnum;
	}
	public synchronized void add(int num) {
		sum+=num;
	}
	public void run() {
		int lsum=0;
		for(int i=0;i<10;i++) {
			lsum+=i+startnum;
		}
		add(lsum);
	}
	public static void main(String[] args) {
		Thread[] threadA=new Thread[10];
		for(int i=0;i<10;i++) {
			threadA[i]=new Work4(10*i+1);
			threadA[i].start();
		}
		for(int i=0;i<10;i++) {
			try {
				threadA[i].join();
			}catch(InterruptedException e) {
				e.printStackTrace();
			}
			
		}
		System.out.println(sum);
	}
	

}
